package 牛客.百度.权数;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        int nums[] = new int[i];
        for(int a = 0;a<i;a++){
            nums[a] = sc.nextInt();
        }
        TreeNode treeNode = new TreeNode(nums[0]);
        int [][] ls = new int[i-1][2];
        for(int a = 0;a<i-1;a++){
             int i3 = sc.nextInt();
             int i4 = sc.nextInt();
            ls [i][0] = i3;
            ls [i][1] = i4;
        }
        for (int a = 0;a <i-1;a++){
            for (int a1 = 0;a1 <i-1;a++){
                boolean b = false;
                if (ls[a][1]==ls[a1][0]){
                    TreeNode tl = new TreeNode(nums[a1]);
                    if(!b){
                        treeNode.leftNode = tl;
                    }else{
                        treeNode.leftNode = tl;
                    }
                }
                if(b){

                }
            }
        }
    }
}
class TreeNode{
    Integer value;
    TreeNode leftNode;
    TreeNode rightNode;

    public TreeNode(Integer value) {
        this.value = value;
    }

    public static void function3(TreeNode t){//先序遍历
        if(t==null){
            return ;
        }else {
            System.out.print(t.value+" ");
            function3(t.leftNode);
            function3(t.rightNode);
        }
    }

    public static void function1(TreeNode treeNode){//左中右遍历
        if(treeNode==null){
            return ;
        }else {
            function1(treeNode.leftNode);
            System.out.print(treeNode.value+" ");
            function1(treeNode.rightNode);
        }
    }
    public static void function2 (TreeNode t){//左右中遍历
        if(t==null){
            return ;
        }else{
            function2(t.leftNode);
            function2(t.rightNode);
            System.out.print(t.value+" ");
        }
    }
}

